package com.jzo2o.market.controller.consumer;

import com.jzo2o.common.expcetions.BadRequestException;
import com.jzo2o.market.enums.ActivityStatusEnum;
import com.jzo2o.market.model.dto.response.SeizeCouponInfoResDTO;
import com.jzo2o.market.service.IActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户端 - 活动管理控制器
 * @author JIAN
 */
@Slf4j
@RestController("consumerActivityController")
@RequestMapping("/consumer/activity")
public class ActivityController {
    @Resource
    private IActivityService activityService;

    /**
     * 用户端查询缓存中的活动信息
     * @param tabType 1 进行中 2 待生效
     */
    @GetMapping("/list")
    public List<SeizeCouponInfoResDTO> listActivity(@RequestParam Integer tabType) {
        ActivityStatusEnum activityStatusEnum;
        if (tabType == 1) {
            activityStatusEnum = ActivityStatusEnum.DISTRIBUTING;
        } else if (tabType == 2) {
            activityStatusEnum = ActivityStatusEnum.NO_DISTRIBUTE;
        } else {
            throw new BadRequestException("请求的状态出错");
        }

        return activityService.getCachedActivity(activityStatusEnum);
    }
}